//
//  WelcomeViewController.swift
//  WEIBO3.0
//
//  Created by beisheng03 on 2017/7/17.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit
import SDWebImage

class WelcomeViewController: UIViewController {
    
    lazy var imageView : UIImageView = {
        let temp = UIImageView()
        
        temp.image = UIImage.defaulIconImage()
        
        return temp
    }()
    
    lazy var lable : UILabel = {
        let lb = UILabel()
        lb.textColor = UIColor.black
        lb.text = "欢迎来到小鲸商城!"
        lb.alpha = 0.0
        return lb
    }()
    


    override func loadView() {
        
        let imageView = UIImageView(image: UIImage(named:"173E109C-7DC2-4830-8329-5685028E9B23"))
        
        view = imageView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(imageView)
        view.addSubview(lable)
        
//        view.backgroundColor = UIColor.viewBgGrey()
        
        
        imageView.frame.size.width = 90
        
        imageView.frame.size.height = 90
        
//        let bot = KScreenH * 0.2
//         - bot - 90
        imageView.frame.origin.y = UIScreen.main.bounds.size.height
        
        
        imageView.center.x = UIScreen.main.bounds.size.width * 0.5

        lable.sizeToFit()
        
        
        imageView.addCornerAndBorder(borderColor: nil, borderWidth: 0.0, masksToBounds: true, cornerRadius: 45)
        
   
        
    }
    
    
    override func viewDidAppear(_ animated: Bool) {
        
        super.viewDidAppear(animated)
        
        // Damping : 阻力系数
        // Velocity : 初始化速度
        // 在Swift中,如果一个枚举类型不设置值:[]/UIViewAnimationOptions(rawValue: 0)
        UIView.animate(withDuration: 3, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 6.0, options: [], animations: {
            
            //            self.view.layoutIfNeeded()
            let bot = KScreenH * 0.7
            self.imageView.frame.origin.y = KScreenH - bot
            
        }) { (_) in
            
            self.lable.center = self.imageView.center
            
            self.lable.frame.origin.y = self.imageView.frame.origin.y + 110
            
            
            UIView.animate(withDuration: 1.0, animations: {
                
                self.lable.alpha = 1.0
                
            }, completion: { (_) in
                
                UIApplication.shared.keyWindow?.rootViewController = TabBarController()
                
                
            })
            
            
        }
        
        
    }

    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

   
}
